-
Notifications
You must be signed in to change notification settings - Fork 13.9k
repr(transparent): do not consider repr(C) types to be 1-ZST #147185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
rustbot has assigned @petrochenkov. Use |
@bors try |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@craterbot check |
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🎉 Experiment
Footnotes
|
This found
EDIT: It later got confirmed that these crates indeed already trigger the lint before this PR. |
@bors try |
repr(transparent): do not consider repr(C) types to be 1-ZST
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🎉 Experiment
Footnotes
|
28ced79
to
2e68050
Compare
2e68050
to
0142b4b
Compare
0142b4b
to
a2b6928
Compare
@rfcbot fcp merge We talked about this in the lang meeting today. We agreed on these answers to #147185 (comment):
Yes, we should phase this out.
We are fine with combining them. This is a pretty rare case so it doesn't seem worth splitting them.
The name we eventually settled on in the meeting was
Given that this is so rare, we agreed to move immediately to deny-by-default, warn in deps. |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
@rfcbot fcp merge |
Team member @tmandry has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns. |
@rfcbot reviewed |
repr_transparent_non_zst_fields
Hm... But these repr(C) types are ZST? I don't quite understand this lint name.
|
The motivation is, e.g.:
I.e., these |
Given that rust-lang/rfcs#3845 hasn't been accepted yet, what should the lint say to explain that a repr(C) type is not a ZST? Something about future compiler versions? |
Right. If we think we might change it in the future, that means we're not actually guaranteeing it today, as a language matter, from the perspective of our stability guarantees. So, e.g., maybe "this type may not be zero-sized on all targets in the future" or even "this type is not guaranteed to be zero-sized on all targets". I.e., maybe it happens to be true today, but in adding this lint, we're disclaiming this guarantee. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
Context: rust-lang/unsafe-code-guidelines#552
This experiments with a suggestion by @RustyYato to stop considering repr(C) types as 1-ZST for the purpose of repr(transparent). If we go with rust-lang/rfcs#3845 (or another approach for fixing repr(C)), they will anyway not be ZST on all targets any more, so this removes a portability hazard. Furthermore, zero-sized repr(C) structs may have to be treated as non-ZST for the win64 ABI (at least that's what gcc/clang do), so allowing them to be ignored in repr(transparent) types is not entirely coherent.
Turns out we already have an FCW for repr(transparent), namely #78586. This extends that lint to also check for repr(C).
TODO: update the lint name and wording to account for its extended scope.